package mc2.ui;
import java.awt.Frame;
import java.awt.Rectangle;

import javax.swing.JScrollPane;

import de.waldemar.ChatIcons;
import de.waldemar.WindowUtils;

import mc2.*;
public class FrmPrivateConv extends javax.swing.JFrame {
    private PrivateConversation _refConv;
    /** Creates new form frmMain */
    public FrmPrivateConv(PrivateConversation iRef) {
        _refConv=iRef;
        initComponents();
        setSize(300,300);
        setVisible(true);
        requestFocus();
        setTitle(_refConv.GetTo().GetName());
        typeBox.requestFocus();
        setIconImage(ChatIcons.ICON_DEFAULT); 
        WindowUtils.optimizedCentrilized(this);   
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        typeBox = new javax.swing.JTextField();
        jScroller = new javax.swing.JScrollPane();
        msgArea = new javax.swing.JTextArea();

        setTitle("Private Conversation");
        setName("frmPrivateConv");
        typeBox.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                typeBoxKeyTyped(evt);
            }
        });

        getContentPane().add(typeBox, java.awt.BorderLayout.SOUTH);

        msgArea.setBackground(new java.awt.Color(244, 241, 241));
        msgArea.setColumns(20);
        msgArea.setEditable(false);
        msgArea.setRows(5);
        jScroller.setViewportView(msgArea);

        getContentPane().add(jScroller, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void typeBoxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_typeBoxKeyTyped
        if(evt.getKeyChar()=='\n')    
            SendMsg();
    }//GEN-LAST:event_typeBoxKeyTyped
    
    
    public void SendMsg(){
        if(typeBox.getText().equals("/clear") || typeBox.getText().equals("/cls") ){
            ClearRecvArea();
        }else
            _refConv.SendMessage(typeBox.getText());
        typeBox.setText("");
    }
    
    public void AddRecvLine(String iMsg){
        msgArea.setText(msgArea.getText()+iMsg+"\n");
        msgArea.scrollRectToVisible(new Rectangle(0,msgArea.getHeight()-20,1,1));
        setState(Frame.NORMAL);
    }
    public void ClearRecvArea(){
        msgArea.setText("");
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScroller;
    private javax.swing.JTextArea msgArea;
    private javax.swing.JTextField typeBox;
    // End of variables declaration//GEN-END:variables
    
}

